package com.ph.demo.current;

/**
 *
 */
public class SynchronizeDemo3 implements Runnable{

    static int i =0;
    public synchronized static void increase(){
        i++;
    }
    @Override
    public void run() {
        for(int j = 0;j<1000000;j++){
            increase();

        }
    }

    public static void main(String[] args) throws Exception{
//        Thread thread = new Thread(new SynchronizeDemo1());
//        Thread thread1 = new Thread(new SynchronizeDemo1());
        Thread thread = new Thread(new SynchronizeDemo3());
        Thread thread1 = new Thread(new SynchronizeDemo3());
        thread.start();
        thread1.start();
        thread1.join();
        thread.join();  //等待线程执行结束
        System.out.println(i);
    }


}

 class test{

     public static void main(String[] args) throws Exception{

         SynchronizeDemo3 synchronizeDemo3 = new SynchronizeDemo3();
         SynchronizeDemo3 synchronizeDemo31 = new SynchronizeDemo3();




         Thread thread = new Thread(synchronizeDemo3);
         Thread thread1 = new Thread(synchronizeDemo31);
         thread.start();
         thread1.start();
         thread1.join();
         thread.join();  //等待线程执行结束
         System.out.println(synchronizeDemo3.i);
         System.out.println(synchronizeDemo31.i);


     }

        }
